package com.ohs.ohsoa.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.LeaveSettingDto;
import com.ohs.ohsoa.system.entity.LeaveSetting;
import com.ohs.ohsoa.system.service.LeavesettingService;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 请假设置controller
 *
 * @author qianjp
 */
@RestController
@RequestMapping("/leavesetting")
@Api(value = " 请假设置", tags = " 请假设置")
public class LeavesettingController {

    @Resource
    private LeavesettingService leavesettingService;

    /**
     * 获取列表信息
     **/
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取部门列表信息")
    public ResultBean<PageInfo<LeaveSetting>> overtimesettingSelectList(@RequestBody PageParam<LeaveSetting> pageParam) {
        List<LeaveSetting> res = leavesettingService.overtimesettingSelectList(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }


    /**
     * 新增请假
     *
     * @param leaveSetting 请假数据
     * @return 新增结果
     */
    @UserLoginToken
    @PostMapping(value = "/insert")
    @ApiOperation(httpMethod = "POST", value = "新增请假")
    public ResultBean<Boolean> leaveSettingInsert(@RequestBody @Valid LeaveSetting leaveSetting, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(leavesettingService.leaveSettingInsert(leaveSetting));
    }

    /**
     * 修改请假
     *
     * @param leaveSetting 请假数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改请假")
    public ResultBean<Boolean> leaveSettingUpdate(@RequestBody @Valid LeaveSetting leaveSetting, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(leavesettingService.leaveSettingUpdate(leaveSetting));
    }

    /**
     * 删除请假
     *
     * @param leaveSettingDto 请假数据
     * @return 删除结果
     */
    @UserLoginToken
    @DeleteMapping(value = "/delete")
    @ApiOperation(httpMethod = "DELETE", value = "删除请假")
    public ResultBean<Boolean> leaveSettingDelete(@RequestBody LeaveSettingDto leaveSettingDto) {
        return ResultBean.success(leavesettingService.leaveSettingDelete(leaveSettingDto));
    }


}
